﻿<UserControl x:Class="SubtitleTools.Shell.DownloadOpenSubtitles"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 mc:Ignorable="d" FontFamily="Tahoma"
			 xmlns:vm="clr-namespace:SubtitleTools.Infrastructure.ViewModels;assembly=SubtitleTools.Infrastructure"
			 xmlns:b="clr-namespace:SubtitleTools.Common.Behaviors;assembly=SubtitleTools.Common"
			 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
			 xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=SubtitleTools.Common"
			 xmlns:conv="clr-namespace:SubtitleTools.Common.Converters;assembly=SubtitleTools.Common"
			 d:DesignHeight="600" d:DesignWidth="600">
	<UserControl.Resources>
		<vm:DownloadOpenSubtitlesViewModel x:Key="vmDownloadOpenSubtitlesViewModel" />
		<conv:Iso639Converter x:Key="convIso639Converter" />
		<conv:VisibilityConverter x:Key="convVisibilityConverter" />
		<DataTemplate x:Key="col0">
			<StackPanel>
				<ProgressBar Value="{Binding Progress}" Height="10" Width="100" />
			</StackPanel>
		</DataTemplate>

		<DataTemplate x:Key="col1">
			<StackPanel HorizontalAlignment="Center">
				<CheckBox HorizontalAlignment="Center" IsChecked="{Binding IsSelected, Mode=TwoWay}" />
			</StackPanel>
		</DataTemplate>

		<DataTemplate x:Key="col3">
			<StackPanel HorizontalAlignment="Center">
				<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding SubFileName}" />
			</StackPanel>
		</DataTemplate>

		<DataTemplate x:Key="col4">
			<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
				<Image Width="16" Height="11" Stretch="UniformToFill"
					   Source="{Binding ISO6393166_1, Converter={StaticResource convIso639Converter}}" Margin="1" />
				<TextBlock HorizontalAlignment="Left" Text="{Binding LanguageName}" Margin="1" />
			</StackPanel>
		</DataTemplate>

		<DataTemplate x:Key="col5">
			<StackPanel HorizontalAlignment="Center">
				<TextBlock HorizontalAlignment="Center" Text="{Binding SubSize}" />
			</StackPanel>
		</DataTemplate>

		<DataTemplate x:Key="col6">
			<StackPanel HorizontalAlignment="Center">
				<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding SubAddDate}" />
			</StackPanel>
		</DataTemplate>
	</UserControl.Resources>
	<extToolkit:BusyIndicator IsBusy="{Binding DownloadOpenSubtitlesGuiData.IsBusy}"                                
							  DataContext="{Binding Source={StaticResource vmDownloadOpenSubtitlesViewModel}}"
							  BusyContent="Please wait..." 
							  DisplayAfter="00:00:00">
		<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height="*" />
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>

				<GroupBox Header="OpenSubtitles.org Search" 
					Margin="5,5,5,1"
					Grid.Row="0">
					<Grid Margin="5">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="auto" />
							<ColumnDefinition Width="*" />
							<ColumnDefinition Width="auto" />
							<ColumnDefinition Width="auto" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>
						<TextBlock VerticalAlignment="Center" Margin="3" Text="Movie file:" Grid.Column="0" />
						<TextBox Text="{Binding DownloadOpenSubtitlesGuiData.MoviePath, Mode=TwoWay}"                                 
							 Grid.Column="1" Margin="3" IsReadOnly="True" />
						<Button Content="..." Margin="3"                                 
								Width="30" Height="25" Grid.Column="2" >
							<i:Interaction.Triggers>
								<i:EventTrigger EventName="Click">
									<b:OpenFileDialogBoxBehavior 
										DialogFilterType="Movie"
										FileDialogDialogResultCommand="{Binding DownloadOpenSubtitlesGuiData.MoviePath, Mode=TwoWay}"/>
								</i:EventTrigger>
							</i:Interaction.Triggers>
						</Button>

						<TextBlock Text="Subtitle language:" Grid.Row="1" Grid.Column="0" 
							   VerticalAlignment="Center" Margin="3" />
						<ComboBox Grid.Column="1" Grid.Row="1" 
								  SelectedValue="{Binding DownloadOpenSubtitlesGuiData.SubLanguage}"
								  ItemsSource="{Binding SubLanguages}"
								  ItemTemplate="{StaticResource col4}"
								  Width="150" HorizontalAlignment="Left" 
								  Margin="3" />
						<Button Content="Search" Grid.Column="0" 
							Height="25"
							Margin="3" Grid.Row="3"
							Command="{Binding DoSearch}"/>
						<ProgressBar Grid.Column="0" 
								 HorizontalAlignment="Stretch" 
								 Grid.Row="2"
								 Value="{Binding DownloadOpenSubtitlesGuiData.Progress}"
								 Height="5"
								 Margin="3" Width="Auto" />
					</Grid>
				</GroupBox>

				<GroupBox Grid.Row="1" Header="Movie info" Margin="5,1">
					<Grid Margin="5">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>

						<TextBlock Grid.Column="0" Grid.Row="0" Text="Name:" Margin="3"/>
						<TextBlock Grid.Column="2" Grid.Row="0" Text="Year:" Margin="3"/>
						<TextBlock Grid.Column="0" Grid.Row="1" Text="OpenSubtitles.Org URL:" Margin="3"/>
						<TextBlock Grid.Column="2" Grid.Row="1" Text="IMDB URL:" Margin="3"/>
						<TextBlock Grid.Row="2" Grid.Column="0" Text="IMDB Rating:" Margin="3"/>

						<TextBlock Grid.Column="1" Grid.Row="0" Foreground="GreenYellow"
							   Text="{Binding DownloadOpenSubtitlesGuiData.MovieName}" Margin="3" HorizontalAlignment="Left" />
						<TextBlock Grid.Column="3" Grid.Row="0" Foreground="GreenYellow"
							   Text="{Binding DownloadOpenSubtitlesGuiData.MovieYear}" Margin="3" HorizontalAlignment="Left" />
						<TextBlock Grid.Row="2" Grid.Column="1" Foreground="GreenYellow"
							   Text="{Binding DownloadOpenSubtitlesGuiData.ImdbRating}" Margin="3" HorizontalAlignment="Left" />

						<TextBlock Grid.Column="3" Grid.Row="1"
							   ToolTip="{Binding DownloadOpenSubtitlesGuiData.ImdbUrl}"
							   Visibility="{Binding DownloadOpenSubtitlesGuiData.ImdbUrl, Converter={StaticResource convVisibilityConverter}}"
							   Foreground="Cyan" HorizontalAlignment="Left"
							   Width="Auto" Margin="3"
							   b:WebHyperlink.LaunchDefaultBrowser="True" VerticalAlignment="Center">  
							<Hyperlink Foreground="Cyan" NavigateUri="{Binding DownloadOpenSubtitlesGuiData.ImdbUrl}">  
								<TextBlock Width="Auto" Foreground="Cyan" Text="{Binding DownloadOpenSubtitlesGuiData.ImdbUrl}"/>  
							</Hyperlink>      
						</TextBlock>

						<TextBlock Grid.Column="1" Grid.Row="1"
							   ToolTip="{Binding DownloadOpenSubtitlesGuiData.OsdbUrl}"
							   Visibility="{Binding DownloadOpenSubtitlesGuiData.OsdbUrl, Converter={StaticResource convVisibilityConverter}}"
							   Foreground="Cyan" HorizontalAlignment="Left"
							   Width="Auto" Margin="3"
							   b:WebHyperlink.LaunchDefaultBrowser="True" VerticalAlignment="Center">  
							<Hyperlink Foreground="Cyan" NavigateUri="{Binding DownloadOpenSubtitlesGuiData.OsdbUrl}">  
								<TextBlock Width="Auto" Foreground="Cyan" Text="{Binding DownloadOpenSubtitlesGuiData.OsdbUrl}"/>  
							</Hyperlink>      
						</TextBlock>
					</Grid>
				</GroupBox>

				<GroupBox Header="Available subtitles at OpenSubtitles.org" 
				  Margin="5,1" MinHeight="200" 
				  Grid.Row="2">
					<ListView ItemsSource="{Binding OsdbItemsData}" 
						  SelectedValue="{Binding DownloadOpenSubtitlesGuiData.SelectedOsdbItem}"
						  Margin="3">
						<ListView.View>
							<GridView>
								<GridViewColumn Width="30"  CellTemplate="{StaticResource col1}"  />
								<GridViewColumn Width="370" Header="FileName" CellTemplate="{StaticResource col3}" />
								<GridViewColumn Width="130" Header="Language" CellTemplate="{StaticResource col4}" />
								<GridViewColumn Width="80" Header="Size" CellTemplate="{StaticResource col5}" />
								<GridViewColumn Width="140" Header="AddDate" CellTemplate="{StaticResource col6}" />
								<GridViewColumn Width="110" Header="Progress" CellTemplate="{StaticResource col0}" />
							</GridView>
						</ListView.View>
						<ListView.ContextMenu>
							<ContextMenu>
								<MenuItem Command="{Binding DoDownloadSelectedItem}" Header="Download selected item">
									<MenuItem.Icon>
										<Image Stretch="UniformToFill" Width="16" Height="16"  Source="images/download.png" 
										   HorizontalAlignment="Center" VerticalAlignment="Center" />
									</MenuItem.Icon>
								</MenuItem>
								<MenuItem Command="{Binding DoDebugDownloadSelectedItem}" Header="Download selected item in its raw format">
									<MenuItem.Icon>
										<Image Stretch="UniformToFill" Width="16" Height="16"  Source="images/debug-step-into-icon.png" 
										   HorizontalAlignment="Center" VerticalAlignment="Center" />
									</MenuItem.Icon>
								</MenuItem>
							</ContextMenu>
						</ListView.ContextMenu>
					</ListView>
				</GroupBox>

				<Button Grid.Row="3" 
					Margin="0,5,5,5"
					Command="{Binding DoDownloadSubtitle}"                    
					Content="Download selected subtitles" 
					HorizontalAlignment="Right" Width="160" Height="28" />
			</Grid>
		</ScrollViewer>
	</extToolkit:BusyIndicator>
</UserControl>
